/**
 * @file wa_obj.h
 *
 */

#ifndef _WA_OBJ_H
#define _WA_OBJ_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
*      INCLUDES
*********************/
#include "wa_conf.h"
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "wa_misc.h"
#include "wa_area.h"
#include "wa_ll.h"
/*********************
*      DEFINES
*********************/

#define WA_OBJ_DEF_W	80
#define WA_OBJ_DEF_H	40

#define WA_CF_HASTRANS			(1<<0)

#define WA_CF_HIDE				(0<<1) 
#define WA_CF_SHOW				(1<<1)
#define WA_CF_ENABLE			(1<<2)

#define WA_CF_DRAG				(1<<3)
#define WA_CF_DRAG_HOR			(1<<4)
#define WA_CF_DRAG_VER			(1<<5)

#define WA_CF_CLICK_TOP			(1<<6)
#define WA_CF_DRAG_PARENT		(1<<7)

#define WA_CF_ANCHOR_RIGHT		(1<<8)
#define WA_CF_ANCHOR_BOTTOM		(1<<9)
#define WA_CF_ANCHOR_LEFT		(1<<10)
#define WA_CF_ANCHOR_TOP		(1<<11)


/**********************
*      TYPEDEFS
**********************/
typedef enum
{
	WA_SIGNAL_CREATE,
	WA_SIGNAL_DELETE,
	WA_SIGNAL_CHILD_CHG,
	WA_SIGNAL_SIZE_CHG,
	WA_SIGNAL_PAINT,
	WA_SIGNAL_MOVE,

	WA_SIGNAL_PRESSED,
	WA_SIGNAL_PRESSING,
	WA_SIGNAL_PRESS_LOST,
	WA_SIGNAL_RELEASED,
	WA_SIGNAL_LONG_PRESS,
	WA_SIGNAL_LONG_PRESS_REP,
	WA_SIGNAL_DRAG_BEGIN,
	WA_SIGNAL_DRAG_END,

	WA_SIGNAL_TIMER,

	WA_SIGNAL_NOTIFY_PARENT,

	WA_SIGNAL_NOTIFY_PRESSED,
	WA_SIGNAL_NOTIFY_RELEASED,
	WA_SIGNAL_NOTIFY_PRESS_LOST,
	WA_SIGNAL_NOTIFY_SEL_CHANGED,
	WA_SIGNAL_NOTIFY_VALUE_CHANGED,

	WA_SIGNAL_SYSTEM_MAX,
}wa_signal;



struct _wa_obj;

typedef struct
{
	int sign_id;
	struct _wa_obj* obj_dst;
	struct _wa_obj* obj_src;
	union
	{
		void* p;
		int v;
		wa_gui_color color;
	} Data;
}wa_sign;

typedef void (*wa_obj_callback)(wa_sign* sign);

typedef struct _wa_obj
{
	wa_area rect;
	struct _wa_obj* par;
	wa_ll child_ll;
	wa_obj_callback cb;
	uint16_t flag;
	wa_area redraw_rect;
	void* ext_attr;
}wa_obj;


/**********************
* GLOBAL PROTOTYPES
**********************/
extern wa_obj top_scr_obj;

void wa_obj_module_init(void);
wa_obj* wa_obj_create(wa_obj* par, wa_obj* copy);
void wa_obj_del(wa_obj* obj);
void wa_obj_clean_child(wa_obj* obj);
void wa_obj_set_parent(wa_obj* obj, wa_obj* par);
int wa_obj_get_rel_x(wa_obj* obj);
int wa_obj_get_rel_y(wa_obj* obj);
int wa_obj_get_width(wa_obj* obj);
int wa_obj_get_height(wa_obj* obj);
void wa_obj_set_pos(wa_obj* obj, int x, int y);
void wa_obj_set_size(wa_obj* obj, int w, int h);
void wa_obj_set_callback(wa_obj* obj, wa_obj_callback cb);
void wa_obj_invalidate(wa_obj* obj);
void wa_obj_part_invalidate(wa_obj* obj, wa_area* part);
wa_obj* wa_obj_get_parent(wa_obj* obj);
wa_obj* wa_obj_get_child_next(wa_obj* obj, wa_obj* child);
wa_obj* wa_obj_get_child_prev(wa_obj* obj, wa_obj* child);
uint16_t wa_obj_count_child(wa_obj* obj);
void* wa_obj_malloc_ext_attr(wa_obj* obj, uint16_t ext_size);
void* wa_obj_get_ext_attr(wa_obj* obj);
wa_obj_callback wa_obj_get_callback(wa_obj* obj);
void wa_obj_to_top(wa_obj* obj);

/**********************
*      MACROS
**********************/


#ifdef __cplusplus
} /* extern "C" */
#endif

#endif
